package com.unitechs.trap.excel.webapi.service.impl.entity;

import com.unitechs.trap.common.pojo.trap.entity.AllData;
import com.unitechs.trap.common.pojo.trap.entity.TrapType;
import com.unitechs.trap.excel.service.ITrapTypeExcelService;
import com.unitechs.trap.excel.webapi.mapper.AllDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

@DubboService
@Slf4j
@Service
public class TrapTypeExcelServiceImpl implements ITrapTypeExcelService {
    @Autowired
    AllDataMapper allDataMapper;

    @Override
    public List<TrapType> listTrapType() {
        List<TrapType> trapTypes = new ArrayList<>();
        List<AllData> allData = allDataMapper.listAllData();
        if (allData==null||allData.isEmpty()){return null;}
        allData.forEach(data -> {
            TrapType trapType = new TrapType();
            BeanUtils.copyProperties(data, trapType);
            trapType.setTrapTypeCode(data.getTrapTypeCode());
            trapType.setAlarmStatus(data.getAllIndex().toString());
            trapType.setTid(UUID.randomUUID().toString());
            LocalDateTime localDateTime = LocalDateTime.now();
            trapType.setCreateTime(localDateTime);
            trapType.setModifyTime(localDateTime);
            trapType.setSpecialty("ALL");
            trapTypes.add(trapType);

        });
        return trapTypes;
    }
}
